package com.syf.test;

import com.syf.core.engine.SyFrameContext;
import com.syf.core.exception.ServiceNotFoundException;
import com.syf.core.service.context.ServiceRequest;
import com.syf.core.service.context.ServiceResponse;
import com.syf.core.service.invoke.ServiceInvokeCallback;
import com.syf.core.test.SyFrameTest;
import com.syf.test.itf.TestService01_ITF;
import com.syf.test.service.TestService01;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

@Slf4j
@SyFrameTest(appBasePackage = "com.syf.test")
public class SyfServiceTestCase {

//    @Qualifier(TestCant.SY_FRAME_CONTEXT_BEAN_NAME)
    @Autowired
    private SyFrameContext syFrameContext;

    @Test
    public void testcase01() throws ServiceNotFoundException {
        ServiceRequest serviceRequest = new ServiceRequest("SyFrameTest");
        TestService01_ITF.RequestData reqDataObj = new TestService01_ITF.RequestData();
        reqDataObj.setUsername("luzhipeng");
        reqDataObj.setPasswd("xxxxx");
        serviceRequest.setDataObj(reqDataObj);
        syFrameContext.getServiceInvoker().invokeService(TestService01.class, serviceRequest, new ServiceInvokeCallback<ServiceResponse>() {
            @Override
            public void onSuccess(ServiceResponse response) {
                log.info("response is {}", response);
            }

            @Override
            public void onFailure(ServiceResponse response) {
                log.info("response is {}", response);
            }

            @Override
            public void throwable(Exception e) {
                log.info("出现异常", e);
            }
        });
    }

    @Test
    public void testcase02() throws ServiceNotFoundException {

        ServiceRequest serviceRequest = new ServiceRequest("SyFrameTest");
        TestService01_ITF.RequestData reqDataObj = new TestService01_ITF.RequestData();
        reqDataObj.setUsername("luzhipeng");
        reqDataObj.setPasswd("xxxxx");
        serviceRequest.setDataObj(reqDataObj);
        syFrameContext.getServiceInvoker().invokeService("notfound", serviceRequest, new ServiceInvokeCallback<ServiceResponse>() {
            @Override
            public void onSuccess(ServiceResponse response) {
                log.info("response is {}", response);
            }

            @Override
            public void onFailure(ServiceResponse response) {
                log.info("response is {}", response);
            }

            @Override
            public void throwable(Exception e) {
                log.info("出现异常", e);
            }
        });
    }

    @Test
    public void testcase03() throws ServiceNotFoundException {
        ServiceRequest serviceRequest = new ServiceRequest("SyFrameTest");
        TestService01_ITF.RequestData reqDataObj = new TestService01_ITF.RequestData();
        reqDataObj.setUsername("luzhipeng");
        reqDataObj.setPasswd("Xxx@1234");
        serviceRequest.setDataObj(reqDataObj);
        syFrameContext.getServiceInvoker().invokeService("11001", serviceRequest, new ServiceInvokeCallback<ServiceResponse>() {
            @Override
            public void onSuccess(ServiceResponse response) {
                log.info("response is {}", response);
            }

            @Override
            public void onFailure(ServiceResponse response) {
                log.info("response is {}", response);
            }

            @Override
            public void throwable(Exception e) {
                log.info("出现异常", e);
            }
        });
    }
}
